package com.gilight.base.service.impl;

import com.gilight.base.base.BusinessException;
import com.gilight.base.dao.SysOperatorLogMapper;
import com.gilight.base.dto.OperatorLogDto;
import com.gilight.base.model.SysOperatorLog;
import com.gilight.base.service.SysOperatorLogService;
import com.gilight.base.util.StringTool;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author xuhs
 * @description 操作日志业务接口实现
 * @date 2019/10/17
 */
@Service
public class SysOperatorLogServiceImpl implements SysOperatorLogService {

    @Autowired
    private SysOperatorLogMapper operatorLogMapper;

    @Override
    public PageInfo findList(OperatorLogDto operatorLogDto) {
        Map<String, Object> map = new HashMap();
            map.put("realName", StringTool.wrapWithPercentChar(operatorLogDto.getRealName()));
        PageHelper.startPage(operatorLogDto.getPageNum(), operatorLogDto.getPageSize());
        List<SysOperatorLog> list = operatorLogMapper.findList(map);
        return new PageInfo(list);
    }

    @Transactional
    @Override
    public void add(SysOperatorLog sysOperatorLog) {
        operatorLogMapper.insertSelective(sysOperatorLog);
    }

    @Transactional
    @Override
    public void delete(Long id) {
        if(null == id){
            throw new BusinessException("更新数据规则失败，未找到相关资源。");
        }
        operatorLogMapper.deleteByPrimaryKey(id);
    }
}
